package com.hong.springboot.listener;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.hong.springboot.api.IUserService;
import com.hong.springboot.entity.User;
import com.hong.springboot.utils.DataResponse;
import lombok.extern.log4j.Log4j2;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

/**
 * @author: csh
 * @Date: 2021/3/16 11:14
 * @Description:用户监听
 */
@Service
@Log4j2
public class UserListener {

    @Reference
    private IUserService userService;

    @KafkaListener(topics = "${kafka.user_topic}")
    public void onMessage(String message){
        log.info("用户message"+message);
        User user = JSONObject.parseObject(message, User.class);
        log.info("springboot获取的用户信息{}", JSONObject.toJSONString(user));
        DataResponse<Boolean> save = userService.reallySave(user);
        log.info("添加结果{}",JSONObject.toJSONString(save));
    }

}
